package com.jacky.api;


import lombok.val;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
@interface ID{
    String value() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@interface Entity{
    String value() default "";
}

@Entity("t_user")
class User{
    @ID("id")
    private Integer id;

    @ID("getId")
    private void getId(){

    }
}

public class AnnotationTests {

    public static void main(String[] args) throws NoSuchFieldException, NoSuchMethodException {
        Entity entity = User.class.getAnnotation(Entity.class);
        System.out.println(entity.value());

        final val id = User.class.getDeclaredField("id").getAnnotation(ID.class);
        System.out.println(id.value());

        final val getId = User.class.getDeclaredMethod("getId").getAnnotation(ID.class);
        System.out.println(getId.value());
    }
}
